import io from 'socket.io-client';

let socket = ''

export const listen = (action) => {

    if (socket === '') socket = io('localhost:3008')

    socket.on('connect', () => {
        action({
            type: 'connect',
            state: 'ok',
            msg: '已连接服务器！'
        })
    })

    socket.on('disconnect', () => {
        action({
            type: 'msg',
            state: 'war',
            msg: '与接服务器链接已断开！'
        })
    });
}

export function emit(action) {
    socket.emit(action.type, action.data)
}